home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15128 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  42 lines

  1. Path: mxsld2.pd.infn.it!LORETI
  2. From: loreti@mxsld2.pd.infn.it (Maurizio Loreti)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: printf problems..
  5. Date: Wed, 17 Apr 1996 12:57:07 GMT
  6. Organization: I.N.F.N. Padova - CDF/CMS VAXcluster
  7. Message-ID: <4l2m9j$1e3s@serra.unipi.it>
  8. References: <4l1ubi$c3p@news.ysu.edu>
  9. Reply-To: loreti@mxsld2.pd.infn.it
  10. NNTP-Posting-Host: mxsld2.pd.infn.it
  11.  
  12. In article <4l1ubi$c3p@news.ysu.edu>, bi287@yfn.ysu.edu (Brian T. Richardson) writes:
  13. >
  14. >    I feel really stupid, but I cannot make printf add zeros
  15. >    before a floating point number..  
  16. >
  17. >    I want it to output '02.11' not '2.11'  
  18. >
  19. >    I tried something like printf(temp, "%O2.2f", myvar)
  20. >    and other varations and nothing has worked for
  21. >    me, I know I'm missing something really obvious..
  22.  
  23. Well, O2.2 is an error; you need a zero, not a letter O, and the width
  24. should be greater than the precision.
  25.  
  26. cmssun1-22> cat foo.c
  27. #include <stdio.h>
  28.  
  29. int main(){
  30.   double x = 2.11;
  31.  
  32.   printf("%010.2f\n", x);
  33.   return 0;
  34. }
  35. cmssun1-23> gcc -ansi -pedantic -Wall foo.c
  36. cmssun1-24> ./a.out
  37. 0000002.11
  38.  
  39. --
  40. Maurizio Loreti                       http://mvxpd5.pd.infn.it/wwwcdf/mlo.html
  41. Un. of Padova, Dept. of Physics - Padova, Italy          loreti@padova.infn.it
  42.